package com.example.module_filemanage.MVVM.Module.QiNiu;

import com.qiniu.android.common.AutoZone;
import com.qiniu.android.common.FixedZone;
import com.qiniu.android.storage.Configuration;
import com.qiniu.android.storage.UploadManager;
import com.qiniu.common.Zone;
import com.qiniu.storage.BucketManager;
import com.qiniu.util.Auth;

import static com.example.module_filemanage.BuildConfig.AK;
import static com.example.module_filemanage.BuildConfig.SK;

/**
 * Created by SJ on 2018/4/18.
 */

public class ConfigManager {
    private static BucketManager bucketManager=null;
    private UploadManager uploadManager=null;
    private ConfigManager() {
        if (bucketManager==null){
            //构造一个带指定Zone对象的配置类
            com.qiniu.storage.Configuration cfg = new com.qiniu.storage.Configuration(Zone.zone0());
//...其他参数参考类注释
            String accessKey =AK;
            String secretKey = SK;
            Auth auth = Auth.create(accessKey, secretKey);
            bucketManager = new BucketManager(auth, cfg);
        }
    }

    public static ConfigManager getInstance() {
        return SingletonHolder.INSTANCE;
    }

    private static class SingletonHolder {
        private static final ConfigManager INSTANCE=new ConfigManager();
    }
    public BucketManager getBucketManager(){
        if (bucketManager==null){
            //构造一个带指定Zone对象的配置类
            com.qiniu.storage.Configuration cfg = new com.qiniu.storage.Configuration(Zone.zone0());
//...其他参数参考类注释
            String accessKey =AK;
            String secretKey = SK;
            Auth auth = Auth.create(accessKey, secretKey);
            bucketManager = new BucketManager(auth, cfg);
        }
        return bucketManager;
    }
    public UploadManager getUploadBuckManager(){
        if (uploadManager!=null)return uploadManager;
        Configuration config = new Configuration.Builder()
                .zone(AutoZone.autoZone)        // 设置区域，指定不同区域的上传域名、备用域名、备用IP。
                .build();
// 重用uploadManager。一般地，只需要创建一个uploadManager对象
         uploadManager=new UploadManager(config);
        return uploadManager;
    }
}
